package com.ysx.behaviour.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysx.behaviour.dto.FollowBehaviorDto;
import com.ysx.behaviour.mapper.ApFollowBehaviorMapper;
import com.ysx.behaviour.pojo.ApBehaviorEntry;
import com.ysx.behaviour.pojo.ApFollowBehavior;
import com.ysx.behaviour.service.ApFollowBehaviorService;
import com.ysx.common.constants.SystemConstants;
import com.ysx.common.utils.RequestHeaderInfoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 * APP关注行为表 服务实现类
 * </p>
 *
 * @author ljh
 * @since 2021-10-07
 */
@Service
public class ApFollowBehaviorServiceImpl extends ServiceImpl<ApFollowBehaviorMapper, ApFollowBehavior> implements ApFollowBehaviorService {
   @Autowired
   private ApBehaviorEntryServiceImpl apBehaviorEntryServiceImpl;

    //1.查询行为实体
    @Override
    public void saveFollowBehavior(FollowBehaviorDto dto) {
        String userId = RequestHeaderInfoUtils.getHeaderUserId();
        //1.查询行为实体
        ApBehaviorEntry apBehaviorEntry = apBehaviorEntryServiceImpl.findByUserIdOrEquipmentId(Integer.parseInt(userId), SystemConstants.TYPE_USER);
        if (apBehaviorEntry != null) {
            //2.判断 如果行为实体为空 则不做处理
            //3.如果 行为实体有值 则保存关注行为数据
            ApFollowBehavior alb = new ApFollowBehavior();
            //设置实体ID
            alb.setEntryId(apBehaviorEntry.getId());
            //设置创建时间
            alb.setCreatedTime(LocalDateTime.now());
            //设置文章的ID
            alb.setArticleId(dto.getArticleId());
            //设置被关注者 用户的ID
            alb.setFollowId(dto.getFollowId());
            save(alb);
        }
    }
}
